package org.googlecode.openapi_java;

import org.json.JSONException;
import org.json.JSONObject;

public class Message implements IVkPossession {
	private String body;
	private String title;
	private long uid;
	private long mid;
	private boolean readstate;
	private long date;
	private boolean out;
	
	private Message(){}
	
    public static Message fromJSON(JSONObject jsonObject, boolean out) throws JSONException {
        Message message = new Message();
        message.uid = jsonObject.getLong("uid");
        message.mid = jsonObject.getLong("mid");
        message.body = jsonObject.getString("body");
        message.title = jsonObject.getString("title");
        message.readstate = jsonObject.getInt("read_state") == 1;
        message.date = jsonObject.getLong("date");
        message.out = out;
        return message;
    }
    
    public static Message fromJSON(JSONObject jsonObject) throws JSONException {
        return fromJSON(jsonObject, jsonObject.getInt("out") == 1);
    }
    

    @Override
    public String toString() {
        return "Message{" +
                "uid=" + uid +
                ", title='" + title + '\'' +
                ", body='" + body + '\'' +
                ", mid=" + mid +
                ", date=" + date +
                ", readstate=" + readstate +
                ", out=" + out + 
                '}';
    }

	public String getBody() {
		return body;
	}

	public String getTitle() {
		return title;
	}

	public long getUid() {
		return uid;
	}

	public long getMid() {
		return mid;
	}

	public boolean getReadstate() {
		return readstate;
	}

	public long getDate() {
		return date;
	}

	public boolean isOut() {
		return out;
	}

	public long getOwner() {
		return uid;
	}
	
	
}
